#include <iostream>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/RollingFileAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Category.hh>
using namespace log4cpp;
using std::cout;
using std::endl;


void test(){
    //输入到标准输出
    OstreamAppender *ap1 = new OstreamAppender("console",&cout);
    PatternLayout *p1 = new PatternLayout();
    p1->setConversionPattern("%d %c [%p] %m%n");
    ap1->setLayout(p1);
    //输出到文件
    FileAppender *ap2 = new FileAppender("file","file_log.data");
    PatternLayout *p2 = new PatternLayout();
    p2->setConversionPattern("%d %c [%p] %m%n");
    ap2->setLayout(p2);
    //输出到回滚文件
    RollingFileAppender *ap3 = new RollingFileAppender("rollingfile",
                                                       "rolling_log.data",
                                                       100,
                                                       6);
    PatternLayout *p3 = new PatternLayout();
    p3->setConversionPattern("%d %c [%p] %m%n");
    ap3->setLayout(p3);

    Category & root = Category::getRoot();
    root.setPriority(Priority::INFO);
    root.addAppender(ap1);
    root.addAppender(ap2);
    root.addAppender(ap3);

    for(int i = 0;i<9;++i){
        root.debug("this is a debug msg");
        root.info("this is a info msg");
        root.alert("this is a alert msg");

    }

}

int main()
{
    

    test ();
    return 0;
}

